package appx.craft.droid.ui;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView;
import appx.craft.droid.R;
import appx.craft.droid.bean.TimeZoneBean;
import appx.craft.droid.uc.TimeListAdapter;
import appx.craft.droid.utils.Const;
import appx.craft.droid.utils.Log;
import appx.craft.droid.utils.Pref;

public class ListScreenActivity extends FragmentActivity {
	
	private static final String TAG = ListScreenActivity.class.getCanonicalName();
	ListView listview_time_message;
	TimeListAdapter mList$Adapter;
	ArrayList<TimeZoneBean> arrayList$TimeZone;
	TimeZoneBean mBean$TimeZone; 
	int itemPosition = -1;
	String marrayTime[];
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.debug(TAG,"[ onCreate ] ");
		setContentView(R.layout.activity_listview_screen);
		
		listview_time_message = (ListView)findViewById(R.id.listview_time_message);
		mList$Adapter = new TimeListAdapter(ListScreenActivity.this);
		
		arrayList$TimeZone = new ArrayList<TimeZoneBean>();
		marrayTime = getResources().getStringArray(R.array.timezone);
		for(int i = 1;i<5;i++){
			mBean$TimeZone = new TimeZoneBean();
			if(i ==1){
				mBean$TimeZone.setIntimageID(R.drawable.location_red);
				mBean$TimeZone.setStrNumber("3");
			}else if(i==2){
				mBean$TimeZone.setIntimageID(R.drawable.location_green);
				mBean$TimeZone.setStrNumber("");
			}else{
				
				mBean$TimeZone.setIntimageID(0);
				mBean$TimeZone.setStrNumber("");
			}
			
			mBean$TimeZone.setStrTitle("Title 1");
			mBean$TimeZone.setStrsubTitle("Hi,what's up ?");
			/**
			 * to load original flow please unCommit below 
			 */
			mBean$TimeZone.setStrTimeDuration(Pref.getValue(Const.DURATION_ITEM+"_"+i, String.valueOf(System.currentTimeMillis())));
//			mBean$TimeZone.setStr$TimeDuration(marrayTime[i-1]);
			
			arrayList$TimeZone.add(mBean$TimeZone);
			
		}
		mList$Adapter.addMoreItems(arrayList$TimeZone);
		
		listview_time_message.setAdapter(mList$Adapter);
		listview_time_message.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> view, View arg1,
					int position, long arg3) {
				itemPosition = position;
				return false;
			}
		});

		/**
		 * register for list view long pressed 
		 */
		registerForContextMenu(listview_time_message);
		
		
	}
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.activity_listing_screen, menu);
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		if(item.getItemId() == R.id.item_delete){
			mList$Adapter.removeItemAtPosition(itemPosition);
			return true;
		}
		return super.onContextItemSelected(item);
	}
	@Override
	protected void onStart() {
		super.onStart();
		Log.debug(TAG,"[ onStart ] ");
	}
	@Override
	protected void onStop() {
		super.onStop();
		Log.debug(TAG,"[ onStop ] ");
	}
	@Override
	protected void onPause() {
		super.onPause();
		Log.debug(TAG,"[ onPause ] ");
	}
	@Override
	protected void onResume() {
		super.onResume();
		Log.debug(TAG,"[ onResume ] ");
		
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		Log.debug(TAG,"[ onDestroy ] ");
	}
	
}
